﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class HotelImages
    {
        #region Common
        public eHotelImages Data;
        public HotelImages()
        {
            Data = new eHotelImages();
		}

        ~HotelImages()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cHotelImages objDAL = new cHotelImages();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cHotelImages objDAL = new cHotelImages();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cHotelImages objInfor = new cHotelImages(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.HotelImages;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }
        //Update nhung cai ma eHotelImages Data dang nam giu thong qua cHotelImages objInfor
        public int Update(int ID)
        {
            int nResult = 0;
            cHotelImages objInfor = new cHotelImages();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }
        private void MappingData(cHotelImages objInfor)
        {
            objInfor.FileName = Data.FileName;
            objInfor.HotelID = Data.HotelID;
        }
        private void ConvertData(cHotelImages objInfor)
        {
            Data.FileName = objInfor.FileName;
            Data.HotelID = objInfor.HotelID;
        }
        public DataTable Search(int AlbumID, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cHotelImages objDAL = new cHotelImages();
            tbResult = objDAL.Search(AlbumID, PageIndex, PageSize, ref  PageCount);
            return tbResult;
        }
        #endregion
    }
}
